package com.ltkj.coupon.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.annotation.RequiresPermissions;
import com.ltkj.coupon.domain.TCouponRule;
import com.ltkj.coupon.service.ITCouponRuleService;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.utils.poi.ExcelUtil;
import com.ltkj.common.core.web.page.TableDataInfo;

/**
 * 优惠券规则Controller
 * 
 * @author ruoyi
 * @date 2023-09-21
 */
@Api(tags = "优惠券规则")
@RestController
@RequestMapping("/couponrule")
public class TCouponRuleController extends BaseController
{
    @Autowired
    private ITCouponRuleService tCouponRuleService;

    /**
     * 查询优惠券规则列表
     */
    @ApiOperation("查询优惠券规则列表")
    @RequiresPermissions("couponrule:couponrule:list")
    @GetMapping("/list")
    public TableDataInfo list(TCouponRule tCouponRule)
    {
        startPage();
        List<TCouponRule> list = tCouponRuleService.selectTCouponRuleList(tCouponRule);
        return getDataTable(list);
    }

    /**
     * 导出优惠券规则列表
     */
    @ApiOperation("导出优惠券规则列表")
    @RequiresPermissions("couponrule:couponrule:export")
    @Log(title = "优惠券规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCouponRule tCouponRule)
    {
        List<TCouponRule> list = tCouponRuleService.selectTCouponRuleList(tCouponRule);
        ExcelUtil<TCouponRule> util = new ExcelUtil<TCouponRule>(TCouponRule.class);
        util.exportExcel(response, list, "优惠券规则数据");
    }

    /**
     * 获取优惠券规则详细信息
     */
    @ApiOperation("获取优惠券规则详细信息")
    @RequiresPermissions("couponrule:couponrule:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tCouponRuleService.selectTCouponRuleById(id));
    }

    /**
     * 新增优惠券规则
     */
    @ApiOperation("新增优惠券规则")
    @RequiresPermissions("couponrule:couponrule:add")
    @Log(title = "优惠券规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCouponRule tCouponRule)
    {
        return toAjax(tCouponRuleService.insertTCouponRule(tCouponRule));
    }

    /**
     * 修改优惠券规则
     */
    @ApiOperation("修改优惠券规则")
    @RequiresPermissions("couponrule:couponrule:edit")
    @Log(title = "优惠券规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCouponRule tCouponRule)
    {
        return toAjax(tCouponRuleService.updateTCouponRule(tCouponRule));
    }

    /**
     * 删除优惠券规则
     */
    @ApiOperation("删除优惠券规则")
    @RequiresPermissions("couponrule:couponrule:remove")
    @Log(title = "优惠券规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tCouponRuleService.deleteTCouponRuleByIds(ids));
    }
}
